package com.config;
import com.intercepter.ParamIntecepter;
import com.intercepter.TokenIntercepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {
    //将拦截器注入到容器
    @Bean
    public TokenIntercepter getTokenInterceptor() {
        return new TokenIntercepter();
    }

    @Bean
    public ParamIntecepter getParamInterceptor() {
        return new ParamIntecepter();
    }
    //进行拦截，我现在就拦截这一个
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/killNode/checkList");
        registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/killNode/auth");
        registry.addInterceptor(getParamInterceptor()).addPathPatterns("/**");

    }


}
//
//
////    @Override
////    public void addCorsMappings(CorsRegistry registry) {
////        registry.addMapping("/**")
////                .allowCredentials(true)
////                .allowedOriginPatterns("*")
////                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
////                .allowedHeaders("*");
////    }
//
//
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(jwtInterceptor())
//               .addPathPatterns("/**") // 拦截所有请求，通过判断token是否合法来决定是否需要登录
//               .excludePathPatterns("/login", "/registry");
//    }
//
//    @Bean
//    public JwtInterceptor jwtInterceptor() {
//        return new JwtInterceptor();
//    }
//}
